package com.leetcode.No0017;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * @program: leetcode
 * @description:
 * @author: wangzhihua
 * @date: 2021-05-31
 */
public class Solution {

	public List<String> letterCombinations(String digits) {
		String empty = "";

		List<String> result = new ArrayList<String>();

		if (digits.length() == 0) {
			return result;
		}

		result.add(empty);

		HashMap<Character, List<Character>> map = new HashMap<Character, List<Character>>();
		map.put('2', Arrays.asList('a', 'b', 'c'));
		map.put('3', Arrays.asList('d', 'e', 'f'));
		map.put('4', Arrays.asList('g', 'h', 'i'));
		map.put('5', Arrays.asList('j', 'k', 'l'));
		map.put('6', Arrays.asList('m', 'n', 'o'));
		map.put('7', Arrays.asList('p', 'q', 'r', 's'));
		map.put('8', Arrays.asList('t', 'u', 'v'));
		map.put('9', Arrays.asList('w', 'x', 'y', 'z'));

		for (int i = 0; i < digits.length(); ++i) {
			List<String> newResult = new ArrayList<String>();
			String strToDel = null;
			do {
				strToDel = result.get(0);
				for (Character ch : map.get(digits.charAt(i))) {
					newResult.add(strToDel + ch);
				}
				result.remove(strToDel);
			} while (result.size() > 0);
			result = newResult;
		}

		result.remove(empty);

		return result;
	}

	@Test
	public void test01() {
		System.out.println(letterCombinations(""));
	}

}
